﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Ongoal.Quotation;
using Ongoal.Quotation.Service.Common;
using Ongoal.Quotation.Service.Interface;
using Ongoal.Quotation.Service.Model;
using Ongoal.Quotation.Service.ViewModel;

namespace Ongoal.Quotation.WebAPI.Controllers
{
    /// <summary>
    /// 用户管理相关接口
    /// </summary>
    public class RoleController : WebAPIBase
    {
        /// <summary>
        /// 实现类接口
        /// </summary>
        private IRoleService _service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public RoleController(IRoleService service)
        { 
            _service = service;
        }
        /// <summary>
        /// 获取角色树
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object GetTreeRole(string keyword) {
            return _service.GetTreeRole(keyword);
        }
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public bool AddRole([FromBody]Role entity) {
            return _service.AddRole(entity);
        }
        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
       [HttpPost]
        public bool UpdateRole([FromBody] Role model) {
            return _service.UpdateRole(model);
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="listid"></param>
        /// <returns></returns>
        [HttpPost]
        public bool deleteRole([FromBody] List<int> listid) {
            return _service.deleteRole(listid);
        }

        /// <summary>
        /// 获取已经授权的用户
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="keyword"></param>
        /// <param name="orgPost"></param>
        /// <returns></returns>
        [HttpGet]
        public object GetUserRole(int roleId,string keyword,string orgPost) {
           return _service.GetUserRole(roleId, keyword,  orgPost);
        }
        /// <summary>
        /// 获取还没有授权的用户
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="keyword"></param>
        /// <param name="orgPost"></param>
        /// <returns></returns>
        [HttpGet]
        public object GetNotUserRole(int roleId, string keyword, string orgPost) {

            return _service.GetNotUserRole(roleId,keyword, orgPost);
        }

        /// <summary>
        /// 分配用户
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public bool AddRoleUser([FromBody]Receiveruviews model) {
            return _service.AddRoleUser(model.uids,model.roleid);
        }

        /// <summary>
        /// 移除用户
        /// </summary>
        /// <param name="tids"></param>
       [HttpPost]
        public bool RemoveRoleUser([FromBody]List<int> tids) {
            return _service.RemoveRoleUser(tids);

        }
        /// <summary>
        /// 获取权限树
        /// </summary>
        /// <returns></returns>
           [HttpGet]
        public object GetAuthorList(int RoleID) {
            return _service.GetAuthorList(RoleID);
        }
        /// <summary>
        /// 授权
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public object AddAuthor([FromBody]Authviews model) {
            return _service.AddAuthor(model.list, model.RoleID);
        }
    }
}
